#line 1 "ext/ohcount_native/ragel_parsers/python.rl"
// python.rl written by Mitchell Foral. mitchell<att>caladbolg<dott>net

/************************* Required for every parser *************************/
#ifndef RAGEL_PYTHON_PARSER
#define RAGEL_PYTHON_PARSER

#include "ragel_parser_macros.h"

// the name of the language
const char *PYTHON_LANG = "python";

// the languages entities
const char *python_entities[] = {
  "space", "comment", "string", "any"
};

// constants associated with the entities
enum {
  PYTHON_SPACE = 0, PYTHON_COMMENT, PYTHON_STRING, PYTHON_ANY
};

/*****************************************************************************/


#line 27 "ext/ohcount_native/ragel_parsers/python.h"
static const char _python_actions[] = {
	0, 1, 1, 1, 7, 1, 9, 1, 
	10, 1, 11, 1, 13, 1, 14, 1, 
	15, 1, 16, 1, 18, 1, 22, 1, 
	23, 1, 24, 1, 25, 1, 26, 1, 
	28, 1, 29, 1, 30, 1, 31, 1, 
	32, 2, 0, 19, 2, 1, 12, 2, 
	1, 18, 2, 3, 2, 2, 4, 2, 
	2, 5, 2, 2, 6, 7, 2, 8, 
	9, 2, 11, 20, 2, 12, 21, 2, 
	14, 27, 2, 17, 12, 2, 17, 14, 
	3, 3, 2, 1, 3, 4, 2, 1, 
	3, 5, 2, 1
};

static const char _python_cond_offsets[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 1, 
	2, 3, 4, 4, 4, 4, 4, 5, 
	6, 7, 8, 8, 9, 10, 11, 11, 
	11, 11, 11, 11, 11, 11, 11, 12, 
	12, 12, 12, 12, 12, 12
};

static const char _python_cond_lengths[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 1, 1, 
	1, 1, 0, 0, 0, 0, 1, 1, 
	1, 1, 0, 1, 1, 1, 0, 0, 
	0, 0, 0, 0, 0, 0, 1, 0, 
	0, 0, 0, 0, 0, 0
};

static const short _python_cond_keys[] = {
	13, 13, 13, 13, 13, 13, 13, 13, 
	13, 13, 13, 13, 13, 13, 13, 13, 
	13, 13, 13, 13, 13, 13, 13, 13, 
	0
};

static const char _python_cond_spaces[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0
};

static const unsigned char _python_key_offsets[] = {
	0, 0, 1, 2, 3, 4, 5, 6, 
	7, 8, 9, 11, 16, 19, 20, 31, 
	42, 53, 64, 65, 70, 73, 74, 85, 
	96, 107, 118, 119, 130, 141, 153, 154, 
	155, 162, 165, 166, 169, 170, 172, 186, 
	188, 189, 192, 193, 194, 196
};

static const short _python_trans_keys[] = {
	34, 34, 34, 34, 39, 39, 39, 39, 
	42, 42, 47, 10, 34, 92, 12, 13, 
	10, 12, 13, 34, 9, 10, 12, 32, 
	34, 269, 525, -128, 11, 14, 127, 9, 
	10, 12, 32, 34, 269, 525, -128, 11, 
	14, 127, 9, 10, 12, 32, 34, 269, 
	525, -128, 11, 14, 127, 9, 10, 12, 
	32, 34, 269, 525, -128, 11, 14, 127, 
	10, 10, 39, 92, 12, 13, 10, 12, 
	13, 39, 9, 10, 12, 32, 39, 269, 
	525, -128, 11, 14, 127, 9, 10, 12, 
	32, 39, 269, 525, -128, 11, 14, 127, 
	9, 10, 12, 32, 39, 269, 525, -128, 
	11, 14, 127, 9, 10, 12, 32, 39, 
	269, 525, -128, 11, 14, 127, 10, 9, 
	10, 12, 32, 42, 269, 525, -128, 11, 
	14, 127, 9, 10, 12, 32, 42, 269, 
	525, -128, 11, 14, 127, 9, 10, 12, 
	32, 42, 47, 269, 525, -128, 11, 14, 
	127, 10, 10, 32, 34, 35, 39, 47, 
	9, 13, 32, 9, 13, 34, 10, 12, 
	13, 39, 42, 47, 9, 10, 12, 32, 
	34, 35, 39, 47, 269, 525, -128, 8, 
	14, 127, 9, 32, 34, 10, 12, 13, 
	39, 39, 42, 47, 10, 0
};

static const char _python_single_lengths[] = {
	0, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 2, 3, 1, 1, 7, 7, 
	7, 7, 1, 3, 1, 1, 7, 7, 
	7, 7, 1, 7, 7, 8, 1, 1, 
	5, 1, 1, 1, 1, 2, 10, 2, 
	1, 1, 1, 1, 2, 1
};

static const char _python_range_lengths[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 1, 1, 0, 2, 2, 
	2, 2, 0, 1, 1, 0, 2, 2, 
	2, 2, 0, 2, 2, 2, 0, 0, 
	1, 1, 0, 1, 0, 0, 2, 0, 
	0, 1, 0, 0, 0, 0
};

static const unsigned char _python_index_offsets[] = {
	0, 0, 2, 4, 6, 8, 10, 12, 
	14, 16, 18, 21, 26, 29, 31, 41, 
	51, 61, 71, 73, 78, 81, 83, 93, 
	103, 113, 123, 125, 135, 145, 156, 158, 
	160, 167, 170, 172, 175, 177, 180, 193, 
	196, 198, 201, 203, 205, 208
};

static const char _python_indicies[] = {
	1, 0, 2, 1, 3, 1, 4, 1, 
	5, 0, 6, 5, 7, 5, 4, 5, 
	9, 8, 9, 4, 8, 10, 12, 13, 
	10, 11, 10, 10, 11, 15, 14, 16, 
	17, 17, 16, 18, 19, 17, 15, 15, 
	10, 21, 22, 22, 21, 23, 24, 22, 
	20, 20, 10, 16, 17, 17, 16, 25, 
	19, 17, 15, 15, 10, 16, 17, 17, 
	16, 26, 19, 17, 15, 15, 10, 17, 
	10, 10, 12, 28, 10, 27, 10, 10, 
	27, 30, 29, 31, 32, 32, 31, 33, 
	34, 32, 30, 30, 10, 36, 37, 37, 
	36, 38, 39, 37, 35, 35, 10, 31, 
	32, 32, 31, 40, 34, 32, 30, 30, 
	10, 31, 32, 32, 31, 41, 34, 32, 
	30, 30, 10, 32, 10, 43, 44, 44, 
	43, 45, 46, 44, 42, 42, 10, 48, 
	49, 49, 48, 50, 51, 49, 47, 47, 
	10, 43, 44, 44, 43, 45, 52, 46, 
	44, 42, 42, 10, 44, 10, 53, 54, 
	56, 57, 58, 59, 60, 56, 55, 56, 
	56, 61, 63, 62, 64, 64, 58, 65, 
	62, 8, 58, 62, 67, 53, 53, 67, 
	68, 69, 70, 71, 72, 73, 66, 66, 
	54, 67, 67, 74, 77, 76, 78, 78, 
	79, 81, 80, 26, 78, 42, 82, 75, 
	53, 83, 0
};

static const char _python_trans_targs[] = {
	32, 2, 3, 4, 32, 6, 7, 8, 
	9, 10, 38, 11, 38, 12, 11, 14, 
	14, 15, 16, 18, 14, 14, 15, 16, 
	18, 17, 38, 19, 20, 19, 22, 22, 
	23, 24, 26, 22, 22, 23, 24, 26, 
	25, 43, 27, 27, 28, 29, 30, 27, 
	27, 28, 29, 30, 38, 38, 0, 32, 
	33, 34, 35, 36, 37, 32, 32, 1, 
	32, 5, 38, 39, 40, 41, 42, 44, 
	31, 45, 38, 38, 11, 13, 38, 41, 
	19, 21, 41, 38
};

static const char _python_trans_actions[] = {
	39, 13, 13, 13, 71, 13, 13, 13, 
	13, 13, 29, 0, 41, 0, 62, 1, 
	0, 0, 1, 0, 88, 56, 56, 88, 
	56, 1, 47, 0, 0, 59, 1, 0, 
	0, 1, 0, 84, 53, 53, 84, 53, 
	1, 1, 1, 0, 0, 1, 0, 80, 
	50, 50, 80, 50, 19, 65, 0, 31, 
	11, 77, 13, 77, 77, 33, 37, 13, 
	35, 13, 68, 7, 74, 44, 74, 74, 
	9, 9, 21, 27, 5, 0, 23, 0, 
	3, 0, 1, 25
};

static const char _python_to_state_actions[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	15, 0, 0, 0, 0, 0, 15, 0, 
	0, 0, 0, 0, 0, 0
};

static const char _python_from_state_actions[] = {
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	17, 0, 0, 0, 0, 0, 17, 0, 
	0, 0, 0, 0, 0, 0
};

static const unsigned char _python_eof_trans[] = {
	0, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 11, 11, 11, 11, 11, 
	11, 11, 11, 11, 11, 11, 11, 11, 
	11, 11, 11, 11, 11, 11, 11, 0, 
	0, 62, 63, 65, 63, 63, 0, 75, 
	76, 79, 76, 79, 76, 84
};

static const int python_start = 32;
static const int python_first_final = 32;
static const int python_error = 0;

static const int python_en_python_line = 38;
static const int python_en_python_entity = 32;

#line 111 "ext/ohcount_native/ragel_parsers/python.rl"


/************************* Required for every parser *************************/

/* Parses a string buffer with Python code.
 *
 * @param *buffer The string to parse.
 * @param length The length of the string to parse.
 * @param count Integer flag specifying whether or not to count lines. If yes,
 *   uses the Ragel machine optimized for counting. Otherwise uses the Ragel
 *   machine optimized for returning entity positions.
 * @param *callback Callback function. If count is set, callback is called for
 *   every line of code, comment, or blank with 'lcode', 'lcomment', and
 *   'lblank' respectively. Otherwise callback is called for each entity found.
 */
void parse_python(char *buffer, int length, int count,
  void (*callback) (const char *lang, const char *entity, int start, int end)
  ) {
  init

  
#line 251 "ext/ohcount_native/ragel_parsers/python.h"
	{
	cs = python_start;
	ts = 0;
	te = 0;
	act = 0;
	}
#line 132 "ext/ohcount_native/ragel_parsers/python.rl"
  cs = (count) ? python_en_python_line : python_en_python_entity;
  
#line 261 "ext/ohcount_native/ragel_parsers/python.h"
	{
	int _klen;
	unsigned int _trans;
	short _widec;
	const char *_acts;
	unsigned int _nacts;
	const short *_keys;

	if ( p == pe )
		goto _test_eof;
	if ( cs == 0 )
		goto _out;
_resume:
	_acts = _python_actions + _python_from_state_actions[cs];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 ) {
		switch ( *_acts++ ) {
	case 16:
#line 1 "ext/ohcount_native/ragel_parsers/python.rl"
	{ts = p;}
	break;
#line 283 "ext/ohcount_native/ragel_parsers/python.h"
		}
	}

	_widec = (*p);
	_klen = _python_cond_lengths[cs];
	_keys = _python_cond_keys + (_python_cond_offsets[cs]*2);
	if ( _klen > 0 ) {
		const short *_lower = _keys;
		const short *_mid;
		const short *_upper = _keys + (_klen<<1) - 2;
		while (1) {
			if ( _upper < _lower )
				break;

			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
			if ( _widec < _mid[0] )
				_upper = _mid - 2;
			else if ( _widec > _mid[1] )
				_lower = _mid + 2;
			else {
				switch ( _python_cond_spaces[_python_cond_offsets[cs] + ((_mid - _keys)>>1)] ) {
	case 0: {
		_widec = (short)(128 + ((*p) - -128));
		if ( 
#line 9 "ext/ohcount_native/ragel_parsers/python.rl"
 p+1 < pe && *(p+1) != '\n'  ) _widec += 256;
		break;
	}
				}
				break;
			}
		}
	}

	_keys = _python_trans_keys + _python_key_offsets[cs];
	_trans = _python_index_offsets[cs];

	_klen = _python_single_lengths[cs];
	if ( _klen > 0 ) {
		const short *_lower = _keys;
		const short *_mid;
		const short *_upper = _keys + _klen - 1;
		while (1) {
			if ( _upper < _lower )
				break;

			_mid = _lower + ((_upper-_lower) >> 1);
			if ( _widec < *_mid )
				_upper = _mid - 1;
			else if ( _widec > *_mid )
				_lower = _mid + 1;
			else {
				_trans += (_mid - _keys);
				goto _match;
			}
		}
		_keys += _klen;
		_trans += _klen;
	}

	_klen = _python_range_lengths[cs];
	if ( _klen > 0 ) {
		const short *_lower = _keys;
		const short *_mid;
		const short *_upper = _keys + (_klen<<1) - 2;
		while (1) {
			if ( _upper < _lower )
				break;

			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
			if ( _widec < _mid[0] )
				_upper = _mid - 2;
			else if ( _widec > _mid[1] )
				_lower = _mid + 2;
			else {
				_trans += ((_mid - _keys)>>1);
				goto _match;
			}
		}
		_trans += _klen;
	}

_match:
	_trans = _python_indicies[_trans];
_eof_trans:
	cs = _python_trans_targs[_trans];

	if ( _python_trans_actions[_trans] == 0 )
		goto _again;

	_acts = _python_actions + _python_trans_actions[_trans];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 )
	{
		switch ( *_acts++ )
		{
	case 0:
#line 53 "ext/ohcount_native/ragel_parsers/python.rl"
	{
  if (!line_contains_code && !line_start) line_start = ts;
  line_contains_code = 1;
}
	break;
	case 1:
#line 58 "ext/ohcount_native/ragel_parsers/python.rl"
	{
  if (!line_contains_code) {
    whole_line_comment = 1;
    if (!line_start) line_start = ts;
  }
}
	break;
	case 2:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }
	break;
	case 3:
#line 50 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = INTERNAL_NL; }
	break;
	case 4:
#line 58 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = INTERNAL_NL; }
	break;
	case 5:
#line 66 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = INTERNAL_NL; }
	break;
	case 6:
#line 76 "ext/ohcount_native/ragel_parsers/python.rl"
	{ p--; }
	break;
	case 7:
#line 76 "ext/ohcount_native/ragel_parsers/python.rl"
	{ p--; }
	break;
	case 8:
#line 79 "ext/ohcount_native/ragel_parsers/python.rl"
	{ p--; }
	break;
	case 9:
#line 79 "ext/ohcount_native/ragel_parsers/python.rl"
	{ p--; }
	break;
	case 10:
#line 84 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = PYTHON_SPACE; }
	break;
	case 11:
#line 87 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = NEWLINE;      }
	break;
	case 12:
#line 88 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = PYTHON_ANY;   }
	break;
	case 13:
#line 106 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = PYTHON_SPACE;   }
	break;
	case 14:
#line 107 "ext/ohcount_native/ragel_parsers/python.rl"
	{ entity = PYTHON_COMMENT; }
	break;
	case 17:
#line 1 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;}
	break;
	case 18:
#line 85 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;}
	break;
	case 19:
#line 86 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;}
	break;
	case 20:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }}
	break;
	case 21:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }}
	break;
	case 22:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }}
	break;
	case 23:
#line 85 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;}
	break;
	case 24:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }}
	break;
	case 25:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }}
	break;
	case 26:
#line 31 "ext/ohcount_native/ragel_parsers/python.rl"
	{{p = ((te))-1;}{
    switch(entity) {
    case PYTHON_SPACE:
      ls
      break;
    case PYTHON_ANY:
      code
      break;
    case INTERNAL_NL:
      std_internal_newline(PYTHON_LANG)
      break;
    case NEWLINE:
      std_newline(PYTHON_LANG)
    }
  }}
	break;
	case 27:
#line 93 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;{
    callback(PYTHON_LANG, python_entities[entity], cint(ts), cint(te));
  }}
	break;
	case 28:
#line 109 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p+1;}
	break;
	case 29:
#line 93 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;{
    callback(PYTHON_LANG, python_entities[entity], cint(ts), cint(te));
  }}
	break;
	case 30:
#line 93 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;{
    callback(PYTHON_LANG, python_entities[entity], cint(ts), cint(te));
  }}
	break;
	case 31:
#line 109 "ext/ohcount_native/ragel_parsers/python.rl"
	{te = p;p--;}
	break;
	case 32:
#line 109 "ext/ohcount_native/ragel_parsers/python.rl"
	{{p = ((te))-1;}}
	break;
#line 616 "ext/ohcount_native/ragel_parsers/python.h"
		}
	}

_again:
	_acts = _python_actions + _python_to_state_actions[cs];
	_nacts = (unsigned int) *_acts++;
	while ( _nacts-- > 0 ) {
		switch ( *_acts++ ) {
	case 15:
#line 1 "ext/ohcount_native/ragel_parsers/python.rl"
	{ts = 0;}
	break;
#line 629 "ext/ohcount_native/ragel_parsers/python.h"
		}
	}

	if ( cs == 0 )
		goto _out;
	if ( ++p != pe )
		goto _resume;
	_test_eof: {}
	if ( p == eof )
	{
	if ( _python_eof_trans[cs] > 0 ) {
		_trans = _python_eof_trans[cs] - 1;
		goto _eof_trans;
	}
	}

	_out: {}
	}
#line 134 "ext/ohcount_native/ragel_parsers/python.rl"

  // if no newline at EOF; callback contents of last line
  if (count) { process_last_line(PYTHON_LANG) }
}

#endif

/*****************************************************************************/
